﻿#region [ License information          ]
/* ************************************************************
 *
 * Copyright (c) Bjørn Bouet Smith, 2012
 *
 * This source code is subject to terms and conditions of 
 * Microsoft Public License (Ms-PL).
 * 
 * A copy of the license can be found in the license.txt
 * file at the root of this distribution. If you can not 
 * locate the License, please send an email to bjornsmith@gmail.com
 * 
 * By using this source code in any fashion, you are 
 * agreeing to be bound by the terms of the Microsoft 
 * Public License.
 *
 * You must not remove this notice, or any other, from this
 * software.
 *
 * ************************************************************/
#endregion

namespace Smith.BuildExtensions.ConfigurationTransformation
{
    /// <summary>
    /// class that can transform a web or app.config template into a build target tailored app.config.
    /// Writes the transformed configuration to the file specified in the transformation parameters.
    /// This class is not doing any actual work, but is just orchestrating the work that has to be done.
    /// </summary>
    public class ConfigTransformationEngine
    {
        private readonly IConfigTransformer transformer;
        private readonly IConfigWriter configWriter;

        /// <summary>
        /// Initializes a new instance of the <see cref="ConfigTransformationEngine"/> class.
        /// </summary>
        /// <param name="transformer">The transformer to use.</param>
        /// <param name="configWriter">The config writer.</param>
        public ConfigTransformationEngine(
            IConfigTransformer transformer,
            IConfigWriter configWriter)
        {
            this.transformer = transformer;
            this.configWriter = configWriter;
        }


        /// <summary>
        /// Does the transformation of the configuration file and writes the output to the specified configuration file.
        /// </summary>
        public void DoTransformation()
        {
            string transformedConfig = transformer.TransformConfiguration();

            configWriter.WriteConfiguration(transformedConfig);
        }
    }
}
